<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/website/common/base.jsp"%>

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>${webname }-账号注册</title>
<%@ include file="/website/common/common.jsp"%>
<link href="${webctx }/css/login.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="${webctx}/js/sms.js"></script>
</head>
<body>
<%@ include file="/website/common/top.jsp"%>
<div id="wrap-main">
    <div class="inner reg">
        <div class="title clearfix">
            <span class="logox188"><a href="${ctx }/website/index.jsp"><img src="${webctx }/images/logo.png"/></a></span>
            <span class="text">会员注册</span>
        </div>
        <div class="main" id="loginpanel">
        	<div class="fr regTxt"><a href="${ctx }/user/showregister">手机注册</a></div>
        	<form action="" method="post" onsubmit="return false">
			<ul class="items">
            	<li class="item">
                	<div class="item-title">用户名：</div>
                	<div class="itemInp-ct">
                    	<div class="ipt norWidthIpt"><input name="loginname" type="text" class="inp" maxlength="12" onchange="checkexistaccount()" placeholder="请输入6-12个字符的用户名" value="" style="height:36px;line-height:36px;"></div>
                    </div>
                    <div class="itemInp-info"></div>
                </li>
				<li class="item">
                	<div class="item-title">手机号码：</div>
                	<div class="itemInp-ct">
                    	<div class="ipt norWidthIpt"><input name="phone" type="text" class="inp" placeholder="请输入手机号码" style="height:36px;line-height:36px;"></div>
                    </div>
                    <div class="itemInp-info"></div>
                </li>
				<li class="item">
                	<div class="item-title">验证码：</div>
                	<div class="itemInp-ct">
                    	<div class="ipt norWidthIpt"><input type="text" name="smscode" class="inp" placeholder="输入验证码" style="width:200px;height:36px;line-height:36px;"></div>
                        <a href="javascript:tosendsms();" class="yzm-btn" id="yzmbtn">发送验证码</a>
                    </div>
                    <div class="itemInp-info"></div>
                </li>
                <li class="item">
                	<div class="item-title">密码：</div>
                	<div class="itemInp-ct">
                    	<input type="text" name="pwd" onfocus="this.type='password'" class="ipt norWidthIpt" placeholder="输入密码"  style="height:36px;line-height:36px;">
                    </div>
                    <div class="itemInp-info"></div>
                </li>
                <li class="item">
                	<div class="item-title">再次输入密码：</div>
                	<div class="itemInp-ct">
                    	<input type="text" name="pwd2" onfocus="this.type='password'" class="ipt norWidthIpt" placeholder="再次输入密码" style="height:36px;line-height:36px;">
                    </div>
                    <div class="itemInp-info"></div>
                </li>
                <li class="item">
                	<div class="itemInp-ct">
                    	<div class="checkTxt" id="J_checkBtn" style=" line-height:30px;"><span class="check"></span>我已仔细查阅并同意<a href="javascript:;" id="xieyibtn">《巨达药网用户协议》</a></div>
                    </div>
                </li>
                <li class="item">
                	<div class="itemInp-ct"><a href="javascript:;" onclick="toregister()" class="reg-btn">注册</a></div>
                </li>
			</ul>
			</form>
        </div>
        <div class="main hide" id="loginok">
        	<div class="loginok"><img src="${webctx }/images/ok.png">恭喜你，注册成功！</div>
        	<div class="loginok-btn"><a href="${ctx }">返回首页</a></div>
        </div>
    </div>
</div>
<%@ include file="/website/common/foot.jsp"%>
</body>
</html>
<script>
var can=true;
$(function(){
	$('#J_checkBtn').click(function(){
		$(this).toggleClass('cur');
		if(this.className.indexOf("cur")!=-1){
			can=false;
			$(".reg-btn").css("background","#dddddd");
		}else{
			can=true;
			$(".reg-btn").css("background","#0daeff");
		}
	})	
	
	$("#xieyibtn").click(function(e){
		window.open(ctx+"/info/info?id=47");
		e.stopPropagation(); 
	})
})
var subing=false;
function toregister(){
	if(!can)return false;
	$(".itemInp-info").text('');
	var checked=true;
	if(!$w.isMobile($("[name='phone']").val())){
		$("[name='phone']").parent().parent().next().text("请输入正确的手机号");
		checked=false;
	}if($("[name='pwd']").val()==''){
		$("[name='pwd']").parent().next().text("请输入密码");
		checked=false;
	}
	if($("[name='pwd']").val().length<6){
		$("[name='pwd']").parent().next().text("至少六位数密码");
		checked=false;
	}
	if($("[name='pwd2']").val()==''){
		$("[name='pwd2']").parent().next().text("请再一次输入密码");
		checked=false;
		return false;
	}
	if($("[name='pwd']").val()!=$("[name='pwd2']").val()){
		$("[name='pwd2']").parent().next().text("两次密码不一致");
		checked=false;
		return false;
	}
	if(!subing && checked){
		checkexistaccount(function(){
			subing=true;
			$(".reg-btn").html('<img src="'+ctx+'/website/images/rr.gif">');
			$w.httpRequest({
				url:apiroot+"/user/register",
				data:{"loginname":$("[name='loginname']").val(),"mobile":$("[name='phone']").val(),"pwd":$("[name='pwd']").val(),"smscode":$("[name='smscode']").val(),"regtype":"account"},
				ok:function(ret){
					var user=ret.Data;
					//$w.setLoginUser(user.userid,user.title,user.phone);
					try{
						sessionStorage.setItem("_newreg_","true");
						sessionStorage.removeItem("_curUrl_");
					}catch(e){}
					window.location.href=ctx+"/user/showlogin";
				},fail:function(ret){
					if(ret.MsgCode=='2')$("[name='phone']").parent().parent().next().text(ret.MsgDesc);
					else if(ret.MsgCode=='3')$("[name='smscode']").parent().parent().next().text(ret.MsgDesc);
					else alert(ret.MsgDesc);
					return false;
				},all:function(){subing=false;$(".reg-btn").html('注册');}
			})
		})
	}
}
function tosendsms(){
	if(!$w.isMobile($("[name='phone']").val())){
		$("[name='phone']").parent().parent().next().text("请输入正确的手机号");
	}else
		sendsms($("[name='phone']").val(),'reg','yzmbtn');
}

function checkexistaccount(backfun){
	$("[name='loginname']").parent().parent().next().text("");
	if($("[name='loginname']").val().length<6){
		$("[name='loginname']").parent().parent().next().text("至少六位字符");
		return;
	}
	$w.httpRequest({
		url:apiroot+"/user/checkAccount",
		data:{"loginname":$("[name='loginname']").val()},
		ok:function(ret){
			if(ret.Data.exist=='true'){$("[name='loginname']").parent().parent().next().text("该账号已被注册!");}
			else{
				$("[name='loginname']").parent().parent().next().html("<font style='color:#00B700'>该账号未被使用</font>");
				if(backfun)backfun();
			}
		}
	})
}
</script>
